home *** CD-ROM | disk | FTP | other *** search
- /*
- * draw.c - miscellaneous drawing routines for Interval.
- *
- */
-
- #include <quickdraw.h>
- #include <memory.h>
- #include <window.h>
- #include <resource.h>
- #include <toolutil.h>
- #include <packages.h>
- #include <control.h>
- #include <desk.h>
- #include <event.h>
- #include <font.h>
-
- #include "ival.h"
- #include "progerr.h"
-
- #define PANEFONT systemFont /* font for labelling panes */
-
- #define PANESTRS 129 /* STR# of labels for all window panes */
- #define P_CNTL 1 /* index of The Control pane label */
- #define P_NAME 2 /* ...The Name pane */
- #define P_NOTE 3 /* ...The Notation pane */
-
- static FontInfo labfinfo; /* pane label font information */
-
- /*
- * fillwindow() - create all the data structures necessary to draw
- * the program's window.
- *
- * Fillwindow() auto-places the rectangles of the window based on the
- * window size and on the width of the names of all the buttons.
- */
-
- fillwindow()
- {
- Rect windrect; /* rect enclosing the window */
- short oldfont; /* original font of this port */
- short numstrs; /* number of strings in the current STR# resource*/
- Rect udrect; /* rect enclosing the updown[] buttons */
- Rect itrect; /* rect enclosing the itype[] buttons */
- Rect isrect; /* rect enclosing the isize[] buttons */
- Point delta; /* a temporary distance */
- short width; /* a width (in pixels) */
- Rect tmprect; /* a temporary variable */
-
- topLeft(windrect) = topLeft(windoc->portRect);
- botRight(windrect) = botRight(windoc->portRect);
-
- oldfont = thePort->txFont;
- TextFont(PANEFONT);
- GetFontInfo(&labfinfo);
- TextFont(oldfont);
-
- /*
- * create the Name pane and its contents --
- * its size determines the size of all other panes.
- */
-
- fillname();
-
- /*
- * create the other rectangles.
- */
-
- cntlrect.left = namerect.left;
- cntlrect.right = namerect.right;
- cntlrect.top = windrect.top + HMARGIN +
- labfinfo.descent + labfinfo.ascent + labfinfo.leading + 1;
- cntlrect.bottom = namerect.top - HMARGIN;
-
- noterect.left = cntlrect.right + 2 * HMARGIN;
- noterect.right = windrect.right - HMARGIN;
- noterect.top = namerect.top;
- noterect.bottom = namerect.bottom;
-
- /*
- * Create the score structures
- * then move the score to the appropriate place in its rect.
- */
-
- getscore();
-
- /*
- * Put the control buttons in their appropriate panes.
- */
-
- fillcntl();
- }
-
- /*
- * makeradcol() - create a column of radio buttons.
- * (actually, any kind of buttons you want)
- */
-
- makeradcol(buttons, procid, strid, firstrect, dh, dv)
- ControlHandle *buttons; /* points to an array of buttons */
- short procid; /* button procID to use */
- short strid; /* ResID of the STR# resource to use */
- Rect *firstrect; /* where to put the first button */
- short dh, dv; /* horz/vert offset for the next button */
- {
- short strnum; /* the current label string id */
- char name[64]; /* name of the current button */
- Rect butrect; /* Rect of the current button */
-
- topLeft(butrect) = topLeft(*firstrect);
- botRight(butrect) = botRight(*firstrect);
-
- strnum = 1;
- while (TRUE) {
- GetIndString(name, strid, strnum);
- if (name[0] == (char) 0) break; /* Exit loop */
- buttons[strnum - 1] =
- NewControl(windoc, &butrect, name,
- TRUE, 0, 0, 1, procid, 0L);
-
- OffsetRect(&butrect, dh, dv);
- ++strnum;
- }
- }
-
- /*
- * redoc() - redraw the program's window.
- * This routine is called to satisfy update events.
- */
-
- redoc()
- {
- GrafPtr saveport;
-
- BeginUpdate(windoc);
- GetPort(&saveport);
- SetPort(windoc);
- EraseRgn(thePort->visRgn);
-
- panelabel(&cntlrect, P_CNTL);
- panelabel(&namerect, P_NAME);
- panelabel(¬erect, P_NOTE);
- DrawControls(windoc);
- drawscore();
-
- drawmouse();
-
- SetPort(saveport);
- EndUpdate(windoc);
- }
-
- /*
- * panelabel() - label the given pane of the window.
- * Assumes: windoc is the current port.
- */
-
- panelabel(prectp, pidx)
- Rect *prectp; /* rect surrounding the pane */
- short pidx; /* string index of the label */
- {
- short oldfont; /* previous font of this port */
- char label[64]; /* (pascal) text of this pane's label */
- short labwid; /* pixel's width of that label */
-
- oldfont = thePort->txFont;
- TextFont(PANEFONT);
-
- MoveTo(prectp->left, prectp->top - 1);
- LineTo(prectp->right, prectp->top - 1);
-
- GetIndString(label, PANESTRS, pidx);
- TextFont(systemFont);
- labwid = StringWidth(label);
- MoveTo((prectp->left + prectp->right) / 2 - labwid / 2,
- prectp->top - 1 - labfinfo.descent);
- DrawString(label);
-
- TextFont(oldfont);
- }
-
- /*
- * strswidth() - return the maximum width of a set of strings.
- * Also count the number of strings.
- * NOTE: width is based on the current font.
- */
-
- short /* width of the widest string */
- strswidth(strid, countp)
- short strid; /* ResID of th STR# resource to examine */
- short *countp; /* where to put the number of strings found */
- {
- short strnum; /* string index within the STR# */
- char name[64]; /* name of the current button */
- short namewidth; /* width of the current name */
- short maxwidth; /* width (pixels) of the widest name */
-
- maxwidth = 0;
- strnum = 1;
- while (TRUE) {
- GetIndString(name, strid, strnum);
- if (name[0] == (char) 0) break; /* Exit loop */
-
- namewidth = StringWidth(name);
- if (maxwidth < namewidth) {
- maxwidth = namewidth;
- }
- ++strnum;
- }
- *countp = strnum - 1;
- return(maxwidth);
- }
-